import Vue from 'vue'
import App from './App.vue'
import store from './store.js'
//导入路由模块，拿到实例对象
import router from './router'

import axios from 'axios'
import ElementUI, { Loading } from 'element-ui' //引入element-ui

//导入 element ui 组件样式
import 'element-ui/lib/theme-chalk/index.css'

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)

//把 ElementUI 注册为 vue 的插件
Vue.use(ElementUI)

Vue.component('axios', axios)

Vue.config.productionTip = false

//挂载 axios
Vue.prototype.axios = axios

声明变量，用来存储 Loading 组件的实例对象（用于后期关闭）
let loadingInstance = null

axios请求拦截器
axios.interceptors.request.use(config =>
  {
    展示 loading 效果
    loadingInstance = Loading.service({fullscreen: true}) //Loading 是element里的效果组件

    配置 Token 认证
    config.headers.Authorization = 'Bearer xxx'
    console.log(config);
  
    return config
  })

  响应拦截器
  axios.interceptors.response.use(response =>
    {
      loadingInstance.close()
      return response
    })



new Vue({
  render: h => h(App),

  //挂载路由的实例对象
  router: router,

  store
}).$mount('#app')
